//
// Created by Administrator on 2023/11/24.
//
#include "iostream"
#include "vector"

using namespace std;

class Solution {
public:
    int moreThanHalfNum_Solution(vector<int> &nums) {
        int count = 1, val = nums[0];
        for (int i = 1; i < nums.size(); ++i) {
            if (val == nums[i])count++;
            else count--;
            if (count == 0) {
                count = 1;
                val = nums[i];
            }
        }
        return val;
    }
};